import { RefGameListItem } from "@/apis/home_page_constant_types"

export const generatePlaceholderGames = (count = 5): RefGameListItem[] => {
    return Array.from({ length: count }, (_, i) => ({
        code: `placeholder_code_${i}`,
        created_at: Date.now(),
        en_name: `Loading...`,
        game_id: `placeholder_${i}`,
        game_type: "0",
        id: `placeholder_id_${i}`,
        img: "", // 可设置 loading 占位图路径
        is_hot: 0,
        is_new: 0,
        maintained: "0",
        online: "0",
        platform_id: "0",
        platform_name: "loading",
        rtp: "",
        sorting: i,
        updated_at: Date.now(),
        updated_name: "",
        updated_uid: "",
        venue_id: "0",
        zh_name: `加载中...`,
    }))
}

/**
 * 1 视讯 2捕鱼 3老虎机 5棋牌 7bingo
 * @param sec 游戏类型 slot | chess 等
 * @returns
 */

export function getGameTypeBySection(sec: string) {
    sec = sec.toLowerCase()
    if (["live"].includes(sec)) {
        return "1"
    }
    if (["fishing"].includes(sec)) {
        return "2"
    }
    if (["slot"].includes(sec)) {
        return "3"
    }
    if (["sport"].includes(sec)) {
        return "4"
    }
    if (["table game", "board games"].includes(sec)) {
        return "5"
    }
    if (["bingo"].includes(sec)) {
        return "7"
    }
    return "0"
}

/**
 *
 * @param ids 解释参数
 * @returns
 */
export function extractIds(ids: string[]) {
    return ids.reduce(
        (acc, id) => {
            const [venue, platform] = id.split("_")
            if (venue) acc.venueIds.push(venue)
            if (platform) acc.platformIds.push(platform)
            return acc
        },
        { venueIds: [] as string[], platformIds: [] as string[] },
    )
}

/**
 *
 * @param url 图片 src
 * @returns
 */
export function getAssetsUrlWithHttp(url: string | undefined): string {
    if (!url) {
        return ""
    }
    if (url.startsWith("http")) {
        return url
    } else {
        return `https://images-ph.oss-ap-southeast-6.aliyuncs.com${url.startsWith("/") ? url : `/${url}`}`
    }
}
